const { DataTypes } = require('sequelize')
const sequelize = require('../config/database')

const Process = sequelize.define('Process', {
  id: {
    type: DataTypes.UUID,
    defaultValue: DataTypes.UUIDV4,
    primaryKey: true
  },
  code: {
    type: DataTypes.STRING,
    allowNull: false,
    unique: true
  },
  name: {
    type: DataTypes.STRING,
    allowNull: false
  },
  description: {
    type: DataTypes.TEXT,
    allowNull: true
  },
  type: {
    type: DataTypes.ENUM('machining', 'assembly', 'testing', 'packaging', 'other'),
    allowNull: false
  },
  standardTime: {
    type: DataTypes.INTEGER,
    allowNull: false,
    comment: '标准工时(分钟)'
  },
  setupTime: {
    type: DataTypes.INTEGER,
    defaultValue: 0,
    comment: '准备时间(分钟)'
  },
  teardownTime: {
    type: DataTypes.INTEGER,
    defaultValue: 0,
    comment: '收尾时间(分钟)'
  },
  equipmentType: {
    type: DataTypes.STRING,
    allowNull: true
  },
  parameters: {
    type: DataTypes.JSON,
    allowNull: true,
    comment: '工艺参数'
  },
  qualityStandards: {
    type: DataTypes.JSON,
    allowNull: true,
    comment: '质量标准'
  },
  isActive: {
    type: DataTypes.BOOLEAN,
    defaultValue: true
  },
  version: {
    type: DataTypes.STRING,
    defaultValue: '1.0'
  }
}, {
  tableName: 'processes',
  timestamps: true
})

module.exports = Process
